package com.tracy.life.utils;

import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;

/**
 * ***********************************************************
 * author: alex
 * time: 16/7/19 下午3:06
 * name:
 * overview:
 * usage:
 * *************************************************************
 */
public class MyHolder extends RecyclerView.ViewHolder {
    //    private Map<Integer, View> map;
    //类似map集合，也可以存取key-value键值对，
    //只不过key值是int类型的时候，效率高。
    private SparseArray<View> map;

    public MyHolder(View itemView) {
        super(itemView);
        map = new SparseArray<>();
    }

    public <T extends View> T getViewById(int itemId) {
        View view = map.get(itemId);
        if (view == null) {
            view = itemView.findViewById(itemId);
            map.put(itemId, view);
        }
        return (T) view;
    }

    public MyHolder setText(String str, int itemId) {
        TextView tv = getViewById(itemId);
        tv.setText(str);
        return this;
    }
    public MyHolder setTextColor(int itemId, int color) {
        TextView tv = getViewById(itemId);
        tv.setTextColor(color);
        return this;
    }
}
